package com.sports.demo.utils;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

public class DateUtils {

    public static final DateTimeFormatter DEFAULT_FORMAT = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

    public static final DateTimeFormatter DEFAULT_FORMAT_CN = DateTimeFormatter.ofPattern("yyyy年MM月dd日 HH:mm");

    public static final DateTimeFormatter DEFAULT_FORMAT_TIMENUMBER = DateTimeFormatter.ofPattern("yyyyMMddHHmmss");

    public static final DateTimeFormatter DEFAULT_FORMAT_SHORTDATENUMBER = DateTimeFormatter.ofPattern("yyMMdd");

    public static final DateTimeFormatter DEFAULT_DATE_FORMAT = DateTimeFormatter.ofPattern("yyyy-MM-dd");

    public static LocalDateTime now() {
        return LocalDateTime.now();
    }

    public static LocalDateTime minusDays(int i) {
        return LocalDateTime.now().minusDays(i);
    }

    public static LocalDateTime minusMinutes(LocalDateTime date, int i) {
        return date.minusMinutes(i);
    }

    public static LocalDateTime parse(String date) {
        if (StringUtils.hasText(date)) {
            return LocalDateTime.parse(date, DEFAULT_FORMAT);
        }
        return null;
    }

    public static LocalDate parseToDate(String date) {
        if (StringUtils.hasText(date)) {
            return LocalDate.parse(date, DEFAULT_DATE_FORMAT);
        }
        return null;
    }

    public static String timeNumber() {
        return DEFAULT_FORMAT_TIMENUMBER.format(now());
    }

    public static String dateNumber() {
        return DEFAULT_FORMAT_SHORTDATENUMBER.format(now());
    }

    public static String toString(LocalDateTime date) {
        return DEFAULT_FORMAT.format(date);
    }

    public static String toString(LocalDate date) {
        return DEFAULT_DATE_FORMAT.format(date);
    }


    public static String toStringCn(LocalDateTime date) {
        return DEFAULT_FORMAT_CN.format(date);
    }
}
